<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace kitego\services\common;

class FileService
{
    /**
     * 路径根据当前系统分隔符适配
     */
    public static function dirReplace(string $path): string
    {
        return str_replace(['/', '\\'], DS, $path);
    }

    /**
     * 删除空目录
     */
    public static function removeEmptyDir(string $path): true
    {
        if (!is_dir($path)) return true;

        $pathHandle = opendir($path);
        readdir($pathHandle);
        readdir($pathHandle);

        if (!readdir($pathHandle)) {
            @rmdir($path);
        }

        return true;
    }
}
